home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / news / inn1.000 / inn1.4sec-linux-src.tar / inn / lib / memcmp.c < prev    next >
C/C++ Source or Header  |  1991-12-20  |  2KB  |  61 lines

  1. /*  $Revision: 1.3 $
  2. **
  3. **  This file has been modified to get it to compile more easily
  4. **  on pre-4.4BSD systems.  Rich $alz, June 1991.
  5. */
  6. #define const /* NULL */
  7. #define void char
  8. #define size_t int
  9. #define NULL 0
  10.  
  11. /*-
  12.  * Copyright (c) 1990 The Regents of the University of California.
  13.  * All rights reserved.
  14.  *
  15.  * This code is derived from software contributed to Berkeley by
  16.  * Chris Torek.
  17.  *
  18.  * Redistribution and use in source and binary forms are permitted
  19.  * provided that: (1) source distributions retain this entire copyright
  20.  * notice and comment, and (2) distributions including binaries display
  21.  * the following acknowledgement:  ``This product includes software
  22.  * developed by the University of California, Berkeley and its contributors''
  23.  * in the documentation or other materials provided with the distribution
  24.  * and in all advertising materials mentioning features or use of this
  25.  * software. Neither the name of the University nor the names of its
  26.  * contributors may be used to endorse or promote products derived
  27.  * from this software without specific prior written permission.
  28.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  29.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  30.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  31.  */
  32.  
  33. #if 0
  34. #if defined(LIBC_SCCS) && !defined(lint)
  35. static char sccsid[] = "@(#)memcmp.c    5.5 (Berkeley) 5/15/90";
  36. #endif /* LIBC_SCCS and not lint */
  37.  
  38. #include <string.h>
  39. #include <sys/stdc.h>
  40. #endif
  41.  
  42. /*
  43.  * Compare memory regions.
  44.  */
  45. int
  46. memcmp(s1, s2, n)
  47.     const void *s1, *s2;
  48.     size_t n;
  49. {
  50.     if (n != 0) {
  51.         register const unsigned char *p1 = (unsigned char *)s1;
  52.         register const unsigned char *p2 = (unsigned char *)s2;
  53.  
  54.         do {
  55.             if (*p1++ != *p2++)
  56.                 return (*--p1 - *--p2);
  57.         } while (--n != 0);
  58.     }
  59.     return (0);
  60. }
  61.